<?php

namespace app\api\controller;

use app\common\controller\Backend;

/**
 * 药品管理
 */
class Medicine extends Backend
{
    /**
     * Medicine模型对象
     * @var object
     * @phpstan-var \app\admin\model\Medicine
     */
    protected object $model;

    protected array|string $preExcludeFields = ['id'];

    protected string|array $quickSearchField = ['id'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new \app\admin\model\Medicine();
    }


    /**
     * 若需重写查看、编辑、删除等方法，请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
     */

     public function listall(){
        $params = $this->request->param();
        $query = $this->model->where([]);
        if(($params['keyword']??'') !== '') $query->where('name|py_code', 'like', "%{$params['keyword']}%");
        $list = $query->order('id desc')->select();
        $list = $list?$list->toArray():[];
        return json(['code' => 0,'msg' => '获取成功', 'data' => $list]);

     }
     public function detail(){
        $params = $this->request->param();
        $id     = $params['id']??0;
        $find = $this->model->where(['id' => $id])->find();
        return json(['code' => 0,'msg' => '获取成功', 'data' => $find]);

     }
}